package com.jhy.suixianglu.daima20230205;

import java.util.LinkedList;
import java.util.Queue;

public class MyStack2 {
    Queue<Integer> queue1;
    Queue<Integer> queue2;

    public MyStack2() {
        queue1 = new LinkedList<>();
        queue2 = new LinkedList<>();
    }

    public void push(int x) {
        // 首先加到辅助队列当中
        queue2.add(x);
        // 将q1当中的元素添加到q2当中
        while(!queue1.isEmpty()){
            queue2.add(queue1.poll());
        }
        // 交换q1和q2
       Queue<Integer> queueTemp = queue1;
        queue1 = queue2;
        queue2 = queueTemp;
    }

    public int pop() {
        return queue1.poll();
    }

    public int top() {
        return queue1.peek();
    }

    public boolean empty() {
        return queue1.isEmpty();
    }

    public void work() {
    }
}
